﻿using BadOCR.Runtime;
using BadOCR.View.ViewModel;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BadOCR.View
{
    /// <summary>
    /// UserConfigView.xaml 的交互逻辑
    /// </summary>
    public partial class UserConfigView : Window
    {
        private UserConfigViewModel _viewModel;
        private UserConfigView()
        {
            InitializeComponent();

            _viewModel = new UserConfigViewModel();
            DataContext = _viewModel;
        }

        /// <summary>
        /// CreateOrActivateWindow
        /// </summary>
        public static void OpenWindow()
        {
            foreach (var window in Application.Current.Windows)
            {
                if (window is UserConfigView userConfigView)
                {
                    //(window as Window).Activate();    // 最小化时无效
                    userConfigView.WindowState = WindowState.Normal;
                    userConfigView.Activate();
                    return;
                }
            }

            new UserConfigView().Show();
        }
    }

    public class OCREngineKind2VisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return Visibility.Collapsed;

            var engineKind = (OCREngineKind)(value as dynamic).Value;

            if (engineKind != OCREngineKind.Baidu)
                return Visibility.Collapsed;

            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
